package com.cloud.bssp.java8.lambda;

import cn.hutool.core.util.RandomUtil;

import java.util.concurrent.CompletableFuture;
import java.util.function.IntPredicate;
import java.util.function.Predicate;

/**
 * @description： TODO
 * @author：weirx
 * @date：2021/10/19 14:17
 * @version：3.0
 */
public class TestIntPredicate {

    public static void main(String[] args) throws InterruptedException {
        Long current = System.currentTimeMillis();

        // 非装箱
        IntPredicate intPredicate = (int i) -> i % 3 == 0;
        CompletableFuture.runAsync(() -> {
            for (int i = 0; i < 10000000; i++) {
                intPredicate.test(RandomUtil.randomInt(100000));
            }
            System.out.println("线程名称：IntPredicate" + Thread.currentThread().getName()+"耗时："+ (System.currentTimeMillis() - current));
        });

        // 装箱
        Predicate<Integer> predicate = (Integer i) -> i % 3 == 0;
        CompletableFuture.runAsync(() -> {
            for (int i = 0; i < 10000000; i++) {
                predicate.test(RandomUtil.randomInt(100000));
            }
            System.out.println("线程名称：Predicate" + Thread.currentThread().getName()+"耗时："+ (System.currentTimeMillis() - current));
        });

        //等待线程执行完成
        Thread.sleep(1000);
    }
}
